package com.company.OfferGuide;

public class 和为s的两个数字 {

    public static void main(String[] args) {
        int[] data = twoSum(new int[]{2, 7, 11, 15}, 9);
        System.out.println(data[0]);
        System.out.println(data[1]);

    }

    public static int[] twoSum(int[] nums, int target) {
        int[] data = new int[2];
        int low = 0, high = nums.length - 1;

        while (nums[low] + nums[high] != target) {
            if (nums[low] + nums[high] > target) {
                high--;
            } else {
                low++;
            }
        }

        data[0] = nums[low];
        data[1] = nums[high];

        return data;
    }

}
